{include file="public/nheader" /}
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="status">
                                <option value="">订单状态</option>
                                <option value="1" {if !empty(input('get.status')) &&
                                    input('get.status')==1}selected{/if}>待发货</option>
                                <option value="2" {if !empty(input('get.status')) &&
                                    input('get.status')==2}selected{/if}>待收货</option>
                                <option value="3" {if !empty(input('get.status')) &&
                                    input('get.status')==3}selected{/if}>已完成</option>
                                <option value="4" {if !empty(input('get.status')) &&
                                    input('get.status')==4}selected{/if}>已取消</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="ordersn" placeholder="订单编号" value="{:input('get.ordersn')}"
                            autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit>搜索</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>
<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    <a class="layui-table-text" lay-open data-title="查看订单" data-area="50%,70%" data-url="/shop/order_edit?id={{d.id}}" >查看订单</a>
    <div class="layui-divider layui-divider-vertical"></div>
    {{#  if(d.status ==0){ }}
    <a class="layui-table-text" style="color:#FF5722" data-url="/shop/order_status?id={{d.id}}&status=4" data-reload="self" data-confirm="" lay-ajax="">取消</a>
    <div class="layui-divider layui-divider-vertical"></div>
    {{# }if(d.status ==1) { }}
    <a class="layui-table-text" data-title="更改物流信息" data-area="30%,40%" callback="edits" data-url="#adminforms"  lay-event="edit">填写快递</a>
<div class="layui-divider layui-divider-vertical"></div>
<a class="layui-table-text" style="color:#FF5722" data-url="/shop/order_status?id={{d.id}}&status=4" data-reload="self" data-confirm="" lay-ajax="">取消</a>
<div class="layui-divider layui-divider-vertical"></div>
<a class="layui-table-text" data-url="/shop/order_status?id={{d.id}}&status=3" data-confirm="" lay-ajax="" data-reload="self">完结</a>
{{# }if(d.status ==2) { }}
<a class="layui-table-text" data-title="更改物流信息" data-area="30%,40%" callback="edits" data-url="#adminforms"  lay-event="edit">更改快递</a>
<div class="layui-divider layui-divider-vertical"></div>
<a class="layui-table-text" data-url="/shop/order_status?id={{d.id}}&status=3" data-confirm="" lay-ajax="" data-reload="self">完结</a>
<div class="layui-divider layui-divider-vertical"></div>
<a class="layui-table-text" style="color:#FF5722" data-url="/shop/order_status?id={{d.id}}&status=4" data-reload="self" data-confirm="" lay-ajax="">取消</a>
{{#  } }}
</script>
<script type="text/html" id="adminforms">
    <div class="layui-fluid layui-bg-white">
        <form class="layui-form layui-form-fixed" lay-filter="adminforms">
            <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>快递名称</label>
            <div class="layui-input-block">
                <input name="postalname"  placeholder="请填写快递名称" type="text" class="layui-input" lay-verify="required" />
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">* </font>快递编号</label>
                <div class="layui-input-block">
                    <input name="postalcode"  placeholder="请填写快递编号" type="number" class="layui-input" lay-verify="required" />
                </div>
        </div>
        <div class="layui-footer layui-form-item layui-center ">
            <button class="layui-btn" lay-filter="submitPage" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closePageDialog" >取消</button>
        </div>
        </form>
    </div>
</script>
{include file="public/nfooter"}
<script>
    layui.use(['admin', 'layer', 'table', 'form'], function () {

        var admin = layui.admin;
        var layer = layui.layer;
        var table = layui.table;        // 表格
        var form = layui.form;
        admin.callback.edits = function (clickthis, colletction, config) {
            var tableThis = colletction.tableThis;
            // 监听权限提交
            form.on("submit(submitPage)", function (post) {

                // 获取用户id
                var pageThat = layui.$(this);
                // 开始POST提交数据
                post.field.id = tableThis.data.id;
                post.field.status = 2;
                layui.$.post("{:url('shop/order_status')}", post.field, function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg);
                        // 关闭当前窗口
                        table.reload('lay-tableList');
                        layer.close(colletction.index);
                    }
                    else {
                        layer.error(res.msg);
                    }
                }, 'json');
                return false;
            })
        }
        /*
         * 初始化表格
        */
        var isTable = table.render({
            elem: "#lay-tableList"
            , url: "{:url()}"
            , page: true
            , size: 'lg'
            , even: true
            , cols: [[
                { type: 'checkbox', width: 60 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                { field: 'ordersn', align: 'center', sort: true, width: 100, title: '订单号' },
                {
                    field: 'name', align: 'center', width: 250, templet: function (d) {
                        return d.name + '&nbsp;' + d.mobile;
                    }, title: '联系方式'
                },
                {
                    field: 'province_text', align: 'center', width: 250, templet: function (d) {
                        return d.province_text + d.city_text + d.area_text + d.street_text;
                    }, title: '地址'
                },
                {
                    field: 'name', align: 'center', width: 250, templet: function (d) {
                        return d.address;
                    }, title: '详细地址'
                },
                {
                    field: 'name', align: 'center', width: 250, templet: function (d) {
                        return '现金:' + d.money + '&nbsp;积分:' + d.total;
                    }, title: '支付方式'
                },
                { field: 'info', width: 200, align: 'center', title: '备注信息' },
                {
                    field: 'status', align: 'center', width: 250, templet: function (d) {
                        var text = '无';
                        if (d.status == 0) {
                            text = '待付款';
                        }
                        if (d.status == 1) {
                            text = '待发货';
                        }
                        if (d.status == 2) {
                            text = '待收货';
                        }
                        if (d.status == 3) {
                            text = '已完成';
                        }
                        if (d.status == 4) {
                            text = '已取消';
                        }
                        return text;
                    }, title: '订单状态'
                },
                { field: 'created', width: 200, align: 'center', title: '添加时间' },
                { align: 'center', toolbar: '#tableBar', width: 300, title: '操作' },
            ]]
        })
    })
</script>
</body>